<style>
    .layui-form-label{
        width: 100px;
    }
    .layui-input-block{
        margin-left: 130px;
    }
</style>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="LAY-list-form">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label" >收货仓库</label>
                </div>
                <div class="layui-inline">
                    <select name="base_warehouse_id" class="selector" lay-search>
                    </select>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">入库业务单号</label>
                    <div class="layui-input-block">
                        <input type="text" name="business_sn" placeholder="请输入入库业务单号" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">入库批次号</label>
                    <div class="layui-input-block">
                        <input type="text" name="batch" placeholder="请输入入库批次号" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">入库类型</label>
                    <div class="layui-input-block">
                        <select name="type" class="selector">
                            <option value="">全部</option>
                            <option value="1">调拨入库</option>
                            <option value="2">采购入库</option>
                            <option value="3">盘盈入库</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <select name="status" class="selector">
                            <option value="">全部</option>
                            <option value="-1">未确定</option>
                            <option value="1">已确定</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <button style="display:none" class="down" lay-submit="" lay-filter="LAY-list-down">下载</button>
                    <button class="layui-btn layuiadmin-btn-useradmin search" lay-submit lay-filter="LAY-list-search">搜索</button>
                    <button type="reset" class="reset layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <table id="LAY-list"  lay-filter="LAY-list"></table>
            <!-- 头部工具栏 -->
            <script type="text/html" id="toolbar">
                <div class="layui-btn-group fl layui-btn-group-jy">
                    <a  class="layui-btn layui-btn-primary layui-btn-sm layui-icon layui-icon-download-circle" lay-event="export">&nbsp;导出</a>
                </div>
            </script>
            <!-- 行内工具 -->
            <script type="text/html" id="LAY-list-toolbar">
                {{# if(d.status == -1){ }}
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-href="Shopwarehousein/edit/id={{d.id}}/type=1" >编辑</a>
                {{# }else{ }}
                <a class="layui-btn layui-btn-xs" lay-href="Shopwarehousein/edit/id={{d.id}}/type=2">详情</a>
                {{# } }}

            </script>
        </div>
    </div>
</div>

<script>
    layui.use(['admin', 'table', 'form','toolJ','laydate','upload'], function () {
        var $ = layui.$
            , admin = layui.admin
            , view = layui.view
            , table = layui.table
            , toolJ = layui.toolJ
            , laydate = layui.laydate
            , form = layui.form
            , user = layui.data('yujiso');
        //用户管理
        table.render({
            elem: '#LAY-list'
            ,url: '/index/Shopwarehousein/getList'
            ,toolbar: '#toolbar'
            ,cellMinWidth:80
            ,defaultToolbar: ['filter']
            ,cols: [[
                {field: 'base_warehouse_name', title: '收货仓库'}
                ,{field: 'batch', title: '入库批次号'}
                ,{field: 'business_sn', title: '入库业务单号'}
                ,{field: 'sku_type', title: 'SKU种类'}
                ,{field: 'type_name', title: '入库类型'}
                ,{field: 'operator', title: '修改人'}
                ,{field: 'create_time', title: '入库时间', width:165}
                ,{field: 'update_time', title: '修改时间', width:165}
                ,{field: 'status_name', title: '状态'}
                ,{fixed: 'right', align:'center',title:'操作', toolbar: '#LAY-list-toolbar', width:120}
            ]]
            ,page: true
            ,limit: 20
            ,text: {none: '暂无相关数据'}
        });
        //监听头部工具栏 操作
        table.on('toolbar(LAY-list)', function (obj) {
            //选中的数据
            var checkStatus = table.checkStatus('LAY-list')
                , data = checkStatus.data;
            //event对应模板的
            switch (obj.event) {
                case 'export':
                    var field = obj.config.where;
                    toolJ.ajax({"data": field,"url":"/index/Shopwarehousein/export"});
                    break;
            }
        });

        //监听行内操作
        table.on('tool(LAY-list)', function(obj){
            var data = obj.data;
            switch (obj.event) {
                case 'disable':
                    toolJ.ajax({"data":{"id":data.id,"status":-1},"url":"/index/Shopwarehousein/disableOrEnable"});
                    break;
                case 'enable':
                    toolJ.ajax({"data":{"id":data.id,"status":1},"url":"/index/Shopwarehousein/disableOrEnable"});
                    break;
            }
        });

        /*动态给下拉框赋值*/
        var warehouse = layui.data(layui.setter.tableName).warehouse;
        var selectHtmlWarehouse = '<option value="">请选择</option>';
        for (var i_ in warehouse) {
            selectHtmlWarehouse += '<option value="' + i_ + '">' + warehouse[i_] + '</option>';
        }
        $("select[name='base_warehouse_id']").append(selectHtmlWarehouse);
        /*重置数据，刷新列表*/
        $('.reset').on('click', function () { //
            $("input").val('');
            $("textarea").val('');
            $(".selector").val('');
            $('.search').click();
        });
        /*重新渲染界面*/
        form.render(null, 'LAY-list-form');
    });
</script>